<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片区 -->
    <el-card>
      <el-row :gutter="20">
        <!--输入框 -->
        <el-col :span="8">
          <el-input
            ref="searchref"
            placeholder="请输入内容"
            v-model="queryData.query"
            clearable
            @clear="getorderList"
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区 -->
      <el-table :data="getorder" style="width: 100%" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="520"
        ></el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="100"
        ></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="100">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="100">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="270">
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="fixdOrder"
            ></el-button>

            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="DoOrder"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 分页 -->
    <el-pagination
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      :page-sizes="[2, 3, 5, 10]"
      :page-size="queryData.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <!-- 修改对话框 -->
    <el-dialog title="修改显示" :visible.sync="isorderShow" width="50%">
      <!-- 内容区 -->
      <el-cascader
        v-model="selectedCityIds"
        :options="cityList"
        :props="{ expandTrigger: 'hover' }"
      ></el-cascader>
      <!-- 按钮区 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="isorderShow = false">取 消</el-button>
        <el-button type="primary">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 物流对话框 -->
    <el-dialog title="物流进度" :visible.sync="OrderShows" width="50%">
      <!-- 内容区 时间线 -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in TimeOrder"
          :key="index"
          :timestamp="activity.ftime"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
      <!-- 按钮区 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="OrderShows = false">取 消</el-button>
        <el-button type="primary">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
// 导入城市
import cityList from './citydata.js'
export default {
  created () {
    this.getorderList()
  },
  data () {
    return {
      queryData: {
        query: '', // 查询参数
        pagenum: 1, // 当前页码
        pagesize: 5 // 每页显示条数
      },
      // 获取 当前页面数据数组
      getorder: [],
      // 容纳个数
      total: 0,
      // 修改内容对话框显示
      isorderShow: false,
      // 物流类容对话框
      OrderShows: false,
      // 城市
      cityList,
      // 选择的城市id
      selectedCityIds: [],
      // 保存的时间线
      TimeOrder: []

    }
  },
  methods: {
    // 获取订单列表函数
    async getorderList () {
      const { data: resData } = await this.$http.get('orders', {
        params: this.queryData
      })
      if (resData.meta.status !== 200) return this.$message.error(resData.meta.msg)
      console.log(resData)
      // 传入数据库数据
      this.getorder = resData.data.goods
      this.total = resData.data.total
    },

    // 页容量改变事件
    handleSizeChange (newsize) {
      this.queryData.pagesize = newsize
      this.getorderList()
    },
    // 页码发生改变
    handleCurrentChange (newnum) {
      this.queryData.pagenum = newnum
      this.getorderList()
    },
    // 点击修改对话框
    fixdOrder () {
      this.isorderShow = true
    },
    // 点击物流对话框
    async DoOrder () {
      this.OrderShows = true
      const { data: resData } = await this.$http.get('/kuaidi/1106975712662')
      console.log(resData)
      if (resData.meta.status !== 200) return this.$message.error(resData.meta.msg)
      // 把时间线 传入空数组
      this.TimeOrder = resData.data
    }
  }

}
</script>

<style lang="postcss" scoped>
</style>
